#include <iostream>
using namespace std;
template <class T>
struct node{
public:
    T element;
    node<T> *next;
    node(){
        this->element=0;
        this->next=NULL;
    }
    node(T &element){
        this->element=element;
        this->next=NULL;
    }
};
template<class T>
class chain: public node<T>
{
public:
    node<T> *firstnode;
    int listsize;
public:
    chain(){
        firstnode=new node<T>();
        firstnode->next=NULL;
        listsize=0;
    }
    chain(const chain<T> &thelist){
        listsize=thelist.listsize;
        node<T> *index_node=thelist.firstnode;
        index_node=thelist.firstnode;
        firstnode=new node<T> (index_node->element);
        index_node=index_node->next;
        node<T> *creatnode=firstnode;
        while(index_node!=NULL){
            creatnode->next =new node<T>(index_node->element);
            creatnode=creatnode->next;
            index_node=index_node->next;
        }
        creatnode->next =NULL;
    }
    ~chain(){
        while(firstnode != NULL){
            node<T> *nextnode=firstnode->next;
            delete firstnode;
            firstnode=nextnode;
        }
    }
    void insertd(int theindex,T theElement){
        node<T> *p=firstnode;
        for(int i=0;i<theindex;i++){
            p=p->next;
        }
        p->next=new node<T>(theElement);
        listsize++;
    }
};
int main()
{
    chain<int> n1;
    chain<int> n2;
    n1.insertd(0, 1);
    n1.insertd(1, 2);
    n1.insertd(2, 3);
    n1.insertd(3, 4);
    n1.insertd(4, 5);
    node<int> *p1=n1.firstnode;
    //跳过头节点
    p1=p1->next;
    int s=n1.listsize;
    for(int i=0;i<s;i++){
        node<int> *p1=n1.firstnode;
        for(int j=0;j<s-i;j++){
            p1=p1->next;
        }
        n2.insertd(i,p1->element);
        cout<<p1->element<<endl;
    }
    return 0;
}
